#ifndef _USERMANAGER_HPP_
#define _USERMANAGER_HPP_

#include "User.hpp"
#include "Camera.hpp"
#include <map>
#include <mutex>
#include <memory>
using std::mutex;
using std::map;
using std::shared_ptr;


namespace wd{

class TcpConnection;

using TcpConnectionptr = shared_ptr<TcpConnection>;

class UserManger{
    class AutoRelease{
    public:
        AutoRelease(){}
        ~AutoRelease(){
            if(_pinstance){
                delete _pinstance;
                _pinstance = nullptr;
            }            
        }

    };
public:
    static UserManger* getInstance();
    void add_user_info(TcpConnectionptr,shared_ptr<User> user);
    void del_user_info(TcpConnectionptr);
    shared_ptr<User> get_single_user(TcpConnectionptr tcpconn);
    void camera_init();
    string get_rtmp(int camera_id);
    string get_rtsp(int camera_id);
    map<TcpConnectionptr,shared_ptr<User>>& get_all_usersinfo();
private:
    UserManger();
    ~UserManger(){}
    UserManger(const UserManger & ) = delete;
    UserManger& operator=(const UserManger&) = delete;
private:
    map<TcpConnectionptr,shared_ptr<User>> _users_info;
    map<int,shared_ptr<Camera>> _cameras;
    mutex _mutex;
    static UserManger * _pinstance;
    static AutoRelease _ar;
};

}


#endif



